#pragma once
class Status
{
public:
	static std::basic_string<TCHAR> GetWin32ErrorMessage(
		__in std::uint32_t ErrorCode)
	{
		TCHAR* message = nullptr;
		if (!::FormatMessage(
			FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, nullptr,
			ErrorCode, LANG_USER_DEFAULT, reinterpret_cast<LPTSTR>(&message), 0,
			nullptr))
		{
			return TEXT("");
		}
		if (!message)
		{
			return TEXT("");
		}
		//auto messageDeleter = std::experimental::make_scope_exit(
		//    [message]() { ::LocalFree(message); });

		const auto length = ::_tcslen(message);
		if (!length)
		{
			return TEXT("");
		}

		if (message[length - 2] == TEXT('\r'))
		{
			message[length - 2] = TEXT('\0');
		}
		return message;
	}
};